package com.demo.arthas;

import com.sun.tools.attach.VirtualMachine;
import com.sun.tools.attach.VirtualMachineDescriptor;

import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.util.List;

/**
 * @author: huangjiazhen
 * @create: 2023/11/20 21:46
 * @description:
 **/
public class Main2 {
    public static void main(String[] args) {
        // 获取所有运行时信息
        RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
        List<String> inputArguments = runtimeMXBean.getInputArguments();

        // 过滤出Java进程
        for (String arg : inputArguments) {
            if (arg.contains("java")) {
                // 输出进程ID和参数信息
                int pid = Integer.parseInt(runtimeMXBean.getName().split("@")[0]);
                System.out.println("Java进程ID：" + pid);
                System.out.println("Java进程参数：" + arg);
            }
        }
    }
}
